package com.central.generator.config;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author yuan
 */
@Data
@NoArgsConstructor
@ApiModel(value = "统一错误返回", description = "统一错误返回")
public class ResultError implements Serializable {

    private static final long serialVersionUID = -6610311777374755822L;
    /**
     * 是否成功
     */
    @ApiModelProperty(value = "返回结果编码", name = "code")
    private Integer code;
    /**
     * 返回数据
     */
    @ApiModelProperty(value = "返回结果数据", name = "data")
    private Object data;
    /**
     * 错误描述
     */
    @ApiModelProperty(value = "返回结果描述", name = "desc")
    private String desc;
    /**
     * 当前时间
     */
    @ApiModelProperty(value = "返回结果时间", name = "time")
    private Long time = System.currentTimeMillis();

    private ResultError(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ResultError error() {
        return new ResultError(ResultCode.CODE99998.getCode(), ResultCode.CODE99998.getDesc());
    }

    public static ResultError error(String desc) {
        return new ResultError(ResultCode.CODE99998.getCode(), desc);
    }

    public static ResultError error(Integer code, String desc) {
        return new ResultError(code, desc);
    }
}